<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script src="../vuejs/vue.js"></script>
    <template id="my-app">
        <button @click="changeFirstName">修改firstName</button>
        <h2>{{fullName}}</h2>
        <h2>{{fullName}}</h2>
        <h2>{{fullName}}</h2>
        <h2>{{fullName}}</h2>
        <h2>{{fullName}}</h2>
        <h2>{{getFullName()}}</h2>
        <h2>{{getFullName()}}</h2>
        <h2>{{getFullName()}}</h2>
        <h2>{{getFullName()}}</h2>
        <h2>{{getFullName()}}</h2>
        <h2>{{getFullName()}}</h2>
    </template>
    <script>
        Vue.createApp({
            template: `#my-app`,
            data() {
                return {
                    firstName: 'Kobe',
                    lastName: 'Bryant',
                    score: 80,
                    message: 'Hello World'
                }
            },
            computed: {
                //计算属性是有缓存的，当我们多次使用计算属性时，计算属性中的计算只会执行一次
                fullName() {
                    console.log("computed的fullName中的计算");
                    return this.firstName + " " + this.lastName;
                },

            },
            methods: {
                getFullName() {
                    console.log("methods的getFullName中的计算");
                    return this.firstName + " " + this.lastName
                },
                changeFirstName(){
                    this.firstName='coby'
                }
            }

        }).mount('#app')
    </script>
</body>

</html>